package com.example.buhui.controlle;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.buhui.dao.EmployeeMapper;
import com.example.buhui.entity.Employee;
import com.example.buhui.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping(value = "/testBoot",method = {RequestMethod.GET,RequestMethod.POST})
public class EmployeeControlle {
  @Resource
  private EmployeeMapper employeeMapper;

    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public List<Employee> findAll(){
        List<Employee> list = employeeMapper.selectList(null);
        return list;
    }

    @RequestMapping(value = "/fenye", method = RequestMethod.GET)
    public List<Employee> fenye(){
        Page<Employee> page = new Page<>(1, 2);
        List<Employee> list =employeeMapper.findListByPage(page).getRecords();
        return list;
    }
    @RequestMapping(value = "/lian", method = RequestMethod.GET)
    public List<Employee> findlian(){
        List<Employee> list = employeeMapper.findLian();
        return list;
    }
    @RequestMapping(value = "/DoChang",method = RequestMethod.GET)
    public Employee DoChange(Employee employee) {
        int count = this.employeeMapper.updateById(employee);
        if (count > 0) {
            return employeeMapper.selectById(employee.getId());
        } else {
            return null;
        }
    }
    @RequestMapping(value = "addOnes", method = RequestMethod.GET)
    public Employee addOnes(Employee employees) {
        employeeMapper.insert(employees);
        return employeeMapper.selectById(employees.getId());
    }
    @RequestMapping(value = "getUser/{id}", method = RequestMethod.GET)
    public Employee GetUser(@PathVariable int id) {
        return employeeMapper.selectById(id);
    }

    @RequestMapping(value = "/DelOnes/{id}",method = RequestMethod.GET)
    public String DelOnes(@PathVariable int id){
        int del = this.employeeMapper.deleteById(id);
        if (del > 0) {
                return "删除成功";
            }else {
            return "删除失败";
            }

    }


}
